package com.ruoyi.bearing.controller;

import java.util.HashMap;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bearing.domain.BearingPretreatment;
import com.ruoyi.bearing.service.IBearingPretreatmentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 数据预处理Controller
 *
 * @author xxx
 * @date 2025-04-07
 */
@RestController
@RequestMapping("/bearing/pretreatment")
public class BearingPretreatmentController extends BaseController
{
    @Autowired
    private IBearingPretreatmentService bearingPretreatmentService;

    /**
     * 查询数据预处理列表
     */
    @PreAuthorize("@ss.hasPermi('bearing:pretreatment:list')")
    @GetMapping("/list")
    public TableDataInfo list(BearingPretreatment bearingPretreatment)
    {
        startPage();
        List<BearingPretreatment> list = bearingPretreatmentService.selectBearingPretreatmentList(bearingPretreatment);
        return getDataTable(list);
    }

    /**
     * 导出数据预处理列表
     */
    @PreAuthorize("@ss.hasPermi('bearing:pretreatment:export')")
    @Log(title = "数据预处理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BearingPretreatment bearingPretreatment)
    {
        List<BearingPretreatment> list = bearingPretreatmentService.selectBearingPretreatmentList(bearingPretreatment);
        ExcelUtil<BearingPretreatment> util = new ExcelUtil<BearingPretreatment>(BearingPretreatment.class);
        util.exportExcel(response, list, "数据预处理数据");
    }

    /**
     * 获取数据预处理详细信息
     */
    @PreAuthorize("@ss.hasPermi('bearing:pretreatment:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bearingPretreatmentService.selectBearingPretreatmentById(id));
    }
    /**
     * 获取数据预处理详细信息
     */
    @PreAuthorize("@ss.hasPermi('bearing:pretreatment:query')")
    @PostMapping(value = "/readAndStoreExcelDataToRedis")
    public AjaxResult readAndStoreExcelDataToRedis(@RequestBody HashMap<String,String> hashMap)
    {
        String path = hashMap.get("path");
        bearingPretreatmentService.readAndStoreExcelDataToRedis(path);
        return success();
    }

    /**
     * 新增数据预处理
     */
    @PreAuthorize("@ss.hasPermi('bearing:pretreatment:add')")
    @Log(title = "数据预处理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BearingPretreatment bearingPretreatment)
    {
        return toAjax(bearingPretreatmentService.insertBearingPretreatment(bearingPretreatment));
    }

    /**
     * 分页获取所有数据预处理信息
     * @param pageNum
     * @param pageSize
     * @return
     */
    @PreAuthorize("@ss.hasPermi('bearing:pretreatment:list')")
    @GetMapping("/getPretreatmentDataPage")
    public AjaxResult getPretreatmentData(Integer pageNum,Integer pageSize){
        return AjaxResult.success(bearingPretreatmentService.getPretreatmentData(pageNum,pageSize));
    }
    /**
     * 获取所有数据预处理信息
     */
    @PreAuthorize("@ss.hasPermi('bearing:pretreatment:list')")
    @GetMapping("/getPretreatmentDataPageAll")
    public AjaxResult getAllPretreatmentData(){
        return AjaxResult.success(bearingPretreatmentService.getAllPretreatmentData());
    }



    /**
     * 修改数据预处理
     */
    @PreAuthorize("@ss.hasPermi('bearing:pretreatment:edit')")
    @Log(title = "数据预处理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BearingPretreatment bearingPretreatment)
    {
        return toAjax(bearingPretreatmentService.updateBearingPretreatment(bearingPretreatment));
    }

    /**
     * 删除数据预处理
     */
    @PreAuthorize("@ss.hasPermi('bearing:pretreatment:remove')")
    @Log(title = "数据预处理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bearingPretreatmentService.deleteBearingPretreatmentByIds(ids));
    }
}
